<?php require_once('connections/con_gl.php'); require_once("excel/excelwriter.class.php");?>

<?php

cekAkses($_SESSION[akses],"KR-1");

mysql_select_db($database_con_gl, $con_gl);

mysql_query("delete from gl_trans where total='0'", $con_gl);

$currentPage = $_SERVER["PHP_SELF"];

//--- get reminder
mysql_select_db($database_con_gl, $con_gl);
$query_getadmin = "SELECT * FROM gl_company";
$getadmin = mysql_query($query_getadmin, $con_gl) or die(mysql_error());
$row_getadmin = mysql_fetch_assoc($getadmin);
$totalRows_getadmin = mysql_num_rows($getadmin);
// ---
$day = date("Y/m/d");
$akh = date("Y/m/d", strtotime("$day +$row_getadmin[r_kontrak] day"));
// ----

$maxRows_data = 8;
$pageNum_data = 0;
if (isset($_GET['pageNum_data'])) {
  $pageNum_data = $_GET['pageNum_data'];
}
$startRow_data = $pageNum_data * $maxRows_data;
$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);
mysql_select_db($database_con_gl, $con_gl);
$query_data = "select a.no, a.tgl, b.gudang, a.biaya, a.pajak, a.total, a.info, a.pbayar, a.mulai, a.sampai, c.nama, c.tlp from gl_kontrak a, gl_gudang b, gl_kontak c where a.gudang = b.id AND c.id=a.kontak AND a.sampai <='$akh'";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_data .= " AND a.gudang='$_SESSION[lokasi]'";

}
if(isset($_GET[cr_txt]) AND $_GET[cr_txt]<>'' AND $_GET[cr_txt]<>'+') { 
$decode_cr = str_replace("+"," ",$_GET[cr_txt]);
$query_data .=" AND (a.no LIKE '%%$decode_cr%%' OR a.info LIKE '%%$decode_cr%%')";
}
if(isset($_GET[cr_kel]) AND $_GET[cr_kel]<>'ALL') { 
$query_data .=" AND a.gudang ='$_GET[gudang]'";
}
$query_data .=" ORDER BY a.tgl desc";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$row_data = mysql_fetch_assoc($data);
$totalRows_data = mysql_num_rows($data);

$queryString_data = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_data") == false && 
        stristr($param, "totalRows_data") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_data = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);
include('include/widget_exportdata.php');
?>
<h1>Daftar  Kontrak akan Berakhir </h1>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable"> 
  <tr valign="top" bgcolor="#FFFFFF" class="hide">
        <td>&nbsp;</td>
<?php

mysql_select_db($database_con_gl, $con_gl);

$query_cr_kel = "SELECT id, gudang FROM gl_gudang";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_cr_kel .= " where id='$_SESSION[lokasi]' ";

}

$query_cr_kel .= " ORDER BY gudang ASC";

$cr_kel = mysql_query($query_cr_kel, $con_gl) or die(mysql_error());

$row_cr_kel = mysql_fetch_assoc($cr_kel);

$totalRows_cr_kel = mysql_num_rows($cr_kel);



?>

		
        <td colspan="5" align="right" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;"><form id="search" name="search" method="post" action="">
      <label>
      <select name="cr_kel" onchange="cr_txt.value=''">
        <option value="ALL">Kantor Cabang</option>
        <?php

do {  

?>
        <option value="<?php echo $row_cr_kel['id']?>"><?php echo $row_cr_kel['gudang']?></option>
        <?php

} while ($row_cr_kel = mysql_fetch_assoc($cr_kel));

  $rows = mysql_num_rows($cr_kel);

  if($rows > 0) {

      mysql_data_seek($cr_kel, 0);

	  $row_cr_kel = mysql_fetch_assoc($cr_kel);

  }

?>
      </select>
      </label>
<label>
      <input name="cr_txt" type="text" id="cr_txt" placeholder="Find by: No.kontrak,Nama Customer"; onclick="this.value='';"<?php echo $_REQUEST['cr_txt'];?>" size="40" maxlength="100" />
      </label>
      <label>
      <input name="Search" type="submit" id="Search" value="Search" />
      </label>
    </form>
	<?php
	if(isset($_POST['Search'])) {
		echo "<script>window.location=\"index.php?component=reminderkontrak&cr_kel=".$_POST[cr_kel]."&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."\";</script>";
	}
	?></td>
  </tr>
  <tr>
    <th width="122"><strong>Jatuh Tempo</strong></th>
    <th width="165"><strong>No. Kontrak </strong></th>
    <th width="145">Nama Pelanggan </th>
    <th width="145">Cabang</th>
    <th width="266">Total </th>
    <th width="425">Keterangan</th>
  </tr>
  <?php if($totalRows_data > 0) { ?>
  <?php do { ?>
    <tr valign="top" bgcolor="#FFFFFF">
      <td><?php tanggal($row_data['tgl'],"tampilkan");?></td>
      <td><?php echo $row_data['no'];?></td>
      <td><?php echo $row_data['nama'];?> - <?php echo $row_data['tlp'];?></td>
      <td><?php echo $row_data['gudang'];?></td>
      <td><?php echo number_format($row_data['biaya'] + $row_data['pajak'] + $row_data['total'],0,',','.');?> / <?php echo $row_data['pbayar'];?> bulan</td>
      <td><strong>Periode Kontrak : </strong><br />
        <?php tanggal($row_data['mulai'],"tampilkan");?> s/d 
        <?php tanggal($row_data['sampai'],"tampilkan");?>
<br />
      <?php echo $row_data['info'];?></td>
    </tr>
    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
	<?php if($totalRows_data > $maxRows_data) { ?>
    <tr class="hide">
      <td colspan="6"><table border="0" align="left">
          <tr>
            <td width="23%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border=0></a>
                <?php } // Show if not first page ?>            </td>
            <td width="31%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border=0></a>
                <?php } // Show if not first page ?>            </td>
            <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
            <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
          </tr>
        </table></td>
    </tr>
	<?php } ?>
   <?php }else{ ?>
  <tr bgcolor="#FFFFFF">
    <td colspan="6">Data tidak ada !!! </td>
  </tr>
  <?php } ?>
  <tr class="hide">
    <td colspan="6">&nbsp;</td>
  </tr>
</table>


<?php
mysql_free_result($data);

mysql_free_result($l_kel);
?>
